//
//  UserInfoManager.swift
//  NewApp
//
//  Created by weijieMac on 2019/4/9.
//  Copyright © 2019 Mac. All rights reserved.
//

import UIKit

let accountLoginInfoKey = "accountLoginInfoKey"

class UserInfoManager: NSObject {
    
    var account = ""
    var password = ""
    var password_ = ""
    
    var limit_time_total_size = ""
    var limit_data_total_size = ""
    var alertPercent = ""
    var data_volume_limit_switch = false
    var data_volume_limit_unit = ""
    var pin_status = "0"
    var isLogin = false {
        didSet {
            NotificationCenter.default.post(name: Notification.Name.init("loginStatusDidChange"), object: nil)
        }
    }
    
    static func shared() -> UserInfoManager {
        return sharedManager
    }
    
    private static let sharedManager: UserInfoManager = {
        let shared = UserInfoManager()
        return shared
    }()
        
    var isConnected = false
    
    var isAutoConnected = true
    
    func saveLoginInfo(account:String,password:String,savePassword:Bool) {
        self.account = account
        self.password_ = password
        if savePassword{
            self.password = password
        }else {
            self.password = ""
        }
        UserDefaults.standard.setValue(["account":account,"password":self.password], forKey: accountLoginInfoKey)
        UserDefaults.standard.synchronize()
    }
    
    func getLoginInfo() {
        guard UserDefaults.standard.value(forKey: accountLoginInfoKey) != nil else {
            return
        }
        self.account = (UserDefaults.standard.value(forKey: accountLoginInfoKey) as! Dictionary )["account"]!
        self.password = (UserDefaults.standard.value(forKey: accountLoginInfoKey) as! Dictionary )["password"]!
    }
}
